#include <iostream>
#include <string>
#include "HashBucket.hpp"   // 假设你把 HashTable 单独写在这个文件里

using namespace std;
using namespace hash_bucket;

// ===============================
// 1. KeyOfT：从 pair<K,V> 提取 key
// ===============================
template<class K, class V>
struct KeyOfPair
{
    const K& operator()(const pair<K, V>& kv) const
    {
        return kv.first;
    }
};

// ===============================
// 2. Hash：对 key 进行哈希（使用 std::hash）
// ===============================
template<class K>
struct MyHash
{
    size_t operator()(const K& key) const
    {
        return std::hash<K>()(key);
    }
};

// ===============================
// 3. 测试函数
// ===============================
int main()
{
    // Key = string, Value = int
    // 使用 pair<string, int> 存储数据
    HashTable<
        string, 
        pair<string, int>, 
        KeyOfPair<string, int>, 
        MyHash<string>
    > ht;

    // 插入数据
    cout << "=== Insert ===\n";
    ht.Insert({"apple", 100});
    ht.Insert({"banana", 200});
    ht.Insert({"orange", 300});
    ht.Insert({"banana", 999}); // 重复插入，应该失败

    // 查找
    cout << "\n=== Find ===\n";
    cout << "Find apple: " << ht.Find("apple") << endl;
    cout << "Find banana: " << ht.Find("banana") << endl;
    cout << "Find xxx: " << ht.Find("xxx") << endl;

    // 删除
    cout << "\n=== Erase ===\n";
    cout << "Erase banana: " << ht.Erase("banana") << endl;
    cout << "Erase banana again: " << ht.Erase("banana") << endl;
    cout << "Find banana: " << ht.Find("banana") << endl;

    return 0;
}
